package com.gym.web.controller.goods.controller;

import java.util.List;

import com.gym.common.utils.poi.ExcelUtil;
import com.gym.system.goods.domain.GymGoods;
import com.gym.system.goods.service.IGymGoodsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.gym.common.annotation.Log;
import com.gym.common.enums.BusinessType;
import com.gym.common.core.controller.BaseController;
import com.gym.common.core.domain.AjaxResult;
import com.gym.common.core.page.TableDataInfo;

/**
 * 器材管理Controller
 *
 * @author administrator
 * @date 2021-04-11
 */
@Controller
@RequestMapping("/goods/goods")
public class GymGoodsController extends BaseController {
    private String prefix = "goods/goods";

    @Autowired
    private IGymGoodsService gymGoodsService;

    @RequiresPermissions("goods:goods:view")
    @GetMapping()
    public String goods() {
        return prefix + "/goods";
    }

    /**
     * 查询器材管理列表
     */
    @RequiresPermissions("goods:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GymGoods gymGoods) {
        startPage();
        List<GymGoods> list = gymGoodsService.selectGymGoodsList(gymGoods);
        return getDataTable(list);
    }

    /**
     * 导出器材管理列表
     */
    @RequiresPermissions("goods:goods:export")
    @Log(title = "器材管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GymGoods gymGoods) {
        List<GymGoods> list = gymGoodsService.selectGymGoodsList(gymGoods);
        ExcelUtil<GymGoods> util = new ExcelUtil<GymGoods>(GymGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增器材管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存器材管理
     */
    @RequiresPermissions("goods:goods:add")
    @Log(title = "器材管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GymGoods gymGoods) {
        return toAjax(gymGoodsService.insertGymGoods(gymGoods));
    }

    /**
     * 修改器材管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        GymGoods gymGoods = gymGoodsService.selectGymGoodsById(id);
        mmap.put("gymGoods", gymGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存器材管理
     */
    @RequiresPermissions("goods:goods:edit")
    @Log(title = "器材管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GymGoods gymGoods) {
        return toAjax(gymGoodsService.updateGymGoods(gymGoods));
    }

    /**
     * 删除器材管理
     */
    @RequiresPermissions("goods:goods:remove")
    @Log(title = "器材管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(gymGoodsService.deleteGymGoodsByIds(ids));
    }
}
